#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cassert>
#include <algorithm>
template<class T>
class seqlist
{
public:
	void insetsq(int sub,T num)
	{
		assert(sub >= 0 && sub <= size);
		if (arr == nullptr)
		{
			push_back(num);
		}
		else
		{
			sqcheck();
			for (int i = size; i > sub; i--)
			{
				arr[i] = arr[i - 1];
			}
			arr[sub] = num;
			size++;
		}
	}
	void Recom(T num)
	{
		assert(arr);
		int des = 0;
		int scr = 0;
		while (scr<size)
		{
			if (arr[scr] != num && scr != des)
			{
				arr[des] = arr[scr];
				des++;
			}
			scr++;
		}
		size = des;
	}
	void Recom(T num, T num1)
	{
		assert(arr);
		for (int i = 0; i < size; i++)
		{
			if (arr[i] == num)
			{
				arr[i] = num1;
			}
		}
	}
	void sqSort()
	{
		assert(arr);
		std::sort(arr, arr + size);
	}
	void pop_front()
	{
		assert(arr);
		for (int i = 0; i < size - 1; i++)
		{
			arr[i] = arr[i + 1];
		}
		size--;
	}
	void sqPrintf()
	{
		for (int i = 0; i < size; i++)
		{
			std::cout << arr[i] << ' ';
		}
		std::cout << std::endl;
	}
	void sqcheck()
	{
		if (size == capacity)
		{
			int newcapacity = capacity == 0 ? 4 : 2 * capacity;
			T* newArr = new T[newcapacity];
			for (int i = 0; i < size; i++)
			{
				newArr[i] = arr[i];
			}
			delete[] arr;
			arr = newArr;
			capacity = newcapacity;
		}
	}
	void pop_back()
	{
		assert(arr);
		size--;
	}
	void push_front(T num = 0)
	{
		int i = size;
		sqcheck();
		for (i = size; i > 0; i--)
		{
			arr[i] = arr[i - 1];
		}
		arr[i] = num;
	}
	void push_back(T num = 0)
	{
		sqcheck();
		arr[size++] = num;
	}
	~seqlist()
	{
		delete[]arr;
	}
private:
	T* arr = nullptr;
	int size = 0;
	int capacity = 0;
};
int main()
{
	seqlist<char> charList;
	charList.push_back('a');
	charList.push_back('b');
	charList.push_back('c');
	charList.push_back('d');
	std::cout << "After push_back: ";
	charList.sqPrintf();
	charList.insetsq(1, 'x');
	std::cout << "After insetsq: ";
	charList.sqPrintf();
	charList.Recom('b');
	std::cout << "After Recom('b'): ";
	charList.sqPrintf();
	charList.Recom('x', 'y');
	std::cout << "After Recom('x', 'y'): ";
	charList.sqPrintf();
	charList.sqSort();
	std::cout << "After sqSort: ";
	charList.sqPrintf();
	charList.pop_front();
	std::cout << "After pop_front: ";
	charList.sqPrintf();
	charList.pop_back();
	std::cout << "After pop_back: ";
	charList.sqPrintf();
	charList.push_front('z');
	std::cout << "After push_front: ";
	charList.sqPrintf();

	return 0;
}